package com.hd.openapi.web.cotenollen;

import com.hd.openapi.common.ResponseResult;
import com.hd.openapi.common.ResultTable;
import com.hd.openapi.entity.Menu;
import com.hd.openapi.entity.Role;
import com.hd.openapi.servies.pageroleser;
import com.sun.org.apache.regexp.internal.RE;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/page")
public class pagedata {
    @Autowired
    private pageroleser a;

    @RequestMapping("/pagedata")
    private ResultTable pagedata(@RequestParam(defaultValue = "1") Integer page,
                                 @RequestParam(defaultValue = "10") Integer limit,
                                 String name){

        ResultTable rt= a.getroledata(page,limit,name);
        return rt;
    }
    @RequestMapping("/update")
    private ResponseResult update(Integer id, Integer status){
        return a.updaterolestatus(id,status);
    }

    @RequestMapping("/menu")
    public List<Integer> menu(Integer roleId){ return a.getrolemenudata(roleId); }

    @RequestMapping("/tree")
    public List<Menu> tree(){ return a.getmenualldata(); }




    @RequestMapping("/assign_menu")
    public ResponseResult assion(Integer roleId,Integer[] menuIds){
        return a.getassigndata(roleId,menuIds);
    }


    @RequestMapping("/add")
    public ResponseResult add(Role role){
        return a.adddata(role);
    }
    @RequestMapping("/upda")
    public ResponseResult upadata(Role role){
        return a.updatadata(role);
    }

}
